#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>

#define LEN 10
#define THREAD_NUM 10

struct param{
  int age;
  char name[LEN];
  int sex;
};

void* print(void *argc){
  struct param *p = (struct param *)argc;
  printf("name:%s\tage:%d\tsex:%d\n", p->name, p->age, p->sex);
}


void* write(void *argc){
  struct param *p = (struct param *)argc;
  (p->age)++;
}

static int x = 0;

int main(){
  pthread_t tid[THREAD_NUM];
  int ret;

  pthread_rwlock_t rwlock;

  struct param user = {
    .sex = 1,
    .name = "shangchao",
    .age = 22,
  };

  for(int i=0; i<THREAD_NUM/2; i++){
    ret = pthread_create(&(tid[i]), NULL, print, (void*)&user);
    if(ret != 0){
      printf("create thread error\n");
      exit(1);
    }
  }
  for(int i=0; i<THREAD_NUM/2; i++){
    ret = pthread_create(&(tid[i + THREAD_NUM /2]), NULL, write, (void*)&user);
    if(ret != 0){
      printf("create thread error\n");
      exit(1);
    }
  }
  for(int i=0; i<THREAD_NUM; i++){
    pthread_join(tid[i], NULL);
  }
  // ret = pthread_create(&tid, NULL, inc, (void*)&x);

  // pthread_join(tid, NULL);
  // printf("x = %d\n", x);
  printf("age:%d\n", user.age);
  return 0;
}